package org.bonorsoft.modules.control.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.service.IService;
import lombok.extern.slf4j.Slf4j;
import org.bonorsoft.common.util.SpringContextUtils;
import org.bonorsoft.modules.control.entity.House;
import org.bonorsoft.modules.control.entity.Population;
import org.bonorsoft.modules.control.entity.Unit;
import org.bonorsoft.modules.control.service.IAddressService;
import org.bonorsoft.modules.control.vo.PopulationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

@Slf4j
@Component
public class PoliceImportUtil {
    @Autowired
    private IAddressService iAddressService;
    private static IAddressService addressService;

    @PostConstruct
    public void init() {
        addressService = iAddressService;
    }


    public static void importHouseSave(List<House> list) {
        list.forEach(PoliceImportUtil::setCommonInfoByAdress);
    }


    private static void setCommonInfoByAdress(House item) {
        addressService.setCommonInfoByAdress(item);
    }

    public static void exportHouseXls(List<House> pageList) {
        pageList.forEach(PoliceImportUtil::getCommonInfoByAdress);
    }

    private static void getCommonInfoByAdress(House house) {
        addressService.getCommonInfoByAdress(house);
    }

    public static void importUnitSave(List<Unit> list) {
        list.forEach(PoliceImportUtil::setUnitByAdress);
    }

    private static void setUnitByAdress(Unit unit) {
        addressService.setUnitByAdress(unit);
    }

    public static void exportUnitXls(List<Unit> pageList) {
        pageList.forEach(PoliceImportUtil::getUnitByAdress);
    }

    private static void getUnitByAdress(Unit unit) {
        addressService.getUnitByAdress(unit);
    }

    public static void importPopulationSave(List<PopulationVo> list) {
        list.forEach(PoliceImportUtil::setPopulationByHouse);
        addPopuAndPhoto(list);
    }

    private static void addPopuAndPhoto(List<PopulationVo> list) {
        addressService.addPopuAndPhoto(list);
    }

    private static void setPopulationByHouse(PopulationVo populationVo) {
        addressService.setPopulationByHouse(populationVo);
    }

    public static void exportPopulationXls(List<PopulationVo> pageList) {
        pageList.forEach(PoliceImportUtil::getPopulationByHouse);
    }

    private static void getPopulationByHouse(PopulationVo populationVo) {
        addressService.getPopulationByHouse(populationVo);
    }
}
